home *** CD-ROM | disk | FTP | other *** search
/ 9-Digit Zip Code Directory / 9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO / z4src.zip / ZIZ5.CPP < prev    next >
C/C++ Source or Header  |  1993-08-09  |  11KB  |  369 lines

  1. //----------------------------------------------------------------------------
  2. //                            MODULE DESCRIPTION
  3. //
  4. //  Module:    ziz5.cpp
  5. //   Title:    9 Digit ZIP Disc Interface
  6. //  Notice:    John M. Weeder
  7. //                 Copyright (c) 1993. All rights reserved.
  8. //             This module contains proprietary information and should be 
  9. //                treated as confidential.
  10. //
  11. //----------------------------------------------------------------------------
  12. //                           MAINTENANCE HISTORY
  13. //
  14. // $Workfile$
  15. // $Revision$
  16. //   $Author$
  17. //     $Date$
  18. //      $Log$    
  19. //
  20. //----------------------------------------------------------------------------
  21. //                             MODULE NARRATIVE
  22. //
  23. //    This module contains code for the class ZI_Z5.
  24. //
  25. //    The code in this module may be written in C++ or C.
  26. //
  27. //    This module is portable to:
  28. //        DOS 3.X+
  29. //        MS Windows 3.X+
  30. //        OS/2 2.X+
  31. //        OS/2 2.0 PM
  32. //
  33. //    The following compilers are supported:
  34. //        MSC 6.0A
  35. //        MSC/C++ 7.0
  36. //        Borland C++ 3.1 for DOS
  37. //        Borland C++ 1.0 for OS/2 2.X
  38. //
  39. //----------------------------------------------------------------------------
  40. #include <zi.hpp>
  41. #define USE_WIN_Z5
  42. #if OS_DOS
  43. #include <zid.hpp>
  44. #elif OS_WINDOWS
  45. #include <ziw.hpp>
  46. #else
  47. #include <zio.hpp>
  48. #endif
  49.  
  50.  
  51. //----------------------------------------------------------------------------
  52. //   Description:    Default constructor
  53. //    Parameters:
  54. //       Returns:
  55. //----------------------------------------------------------------------------
  56. FN_M ZI_Z5::ZI_Z5(PCSZ _pcszZip5)
  57. : ZN_WINDOW("WIN_Z5", ZN_LOAD_CENTER|ZN_LOAD_HELPBAR|ZN_LOAD_NO_SHOW)
  58. {
  59.     ZI_Z5::Initialize(CL_INIT_CLASS);
  60.     pcszZip5 = _pcszZip5;
  61.     Setup();
  62. }
  63.  
  64.  
  65. //----------------------------------------------------------------------------
  66. //   Description:    Destructor
  67. //    Parameters:
  68. //       Returns:    
  69. //----------------------------------------------------------------------------
  70. FN_M ZI_Z5::~ZI_Z5()
  71. {
  72.     ZI_Z5::Destroy(FALSE);
  73.     Terminate();
  74. }
  75.  
  76.  
  77. //----------------------------------------------------------------------------
  78. //   Description:    This function attempts to make a partial match to a state
  79. //                          name and place the virtual list selector on that state.
  80. //    Parameters:
  81. //       Returns:    TRUE if successful.
  82. //----------------------------------------------------------------------------
  83. VOID FN_M ZI_Z5::BestCity()
  84. {
  85.     Z4_CS csNext;
  86.  
  87.     if (!Z4_INQ::cs_file.Record(Z4_INQ::cs, Z4_INQ::z5.arecid[0]))
  88.         return ;
  89.  
  90.     for (SIZET i = 1; i < Z4_INQ::z5.cCities && Z4_INQ::cs.facility != Z4_FACILITY_PO; ++i)
  91.         {
  92.         if (!Z4_INQ::cs_file.Record(csNext, Z4_INQ::z5.arecid[i]))
  93.             return ;
  94.         if (csNext.facility < Z4_INQ::cs.facility)
  95.             Z4_INQ::cs = csNext;
  96.         }
  97.     return ;
  98. }
  99.  
  100.  
  101. //----------------------------------------------------------------------------
  102. //   Description:    This function attempts to make a partial match to a state
  103. //                          name and place the virtual list selector on that state.
  104. //    Parameters:
  105. //       Returns:    TRUE if successful.
  106. //----------------------------------------------------------------------------
  107. VOID FN_M ZI_Z5::CheckMatch()
  108. {
  109.     PCSZ pcsz = GetString(FID(STR_SEARCH));
  110.     if (pcsz && fInit)
  111.         {
  112.         CHAR szWork[80];
  113.         PSZ psz1;
  114.         PCSZ psz2;
  115.  
  116.         psz1 = szWork;
  117.         psz2 = pcsz;
  118.         for (; psz2[0]; ++psz2)
  119.             if (isascii(psz2[0]) && isdigit(psz2[0]))
  120.                 *psz1++ = *psz2;
  121.         *psz1 = '\0';
  122.         if (stricmp(szLastMatch, szWork) == 0)
  123.             return ;
  124.         strcpy(szLastMatch, szWork);
  125.         if (strlen(szLastMatch) > 5)
  126.             return ;
  127.         if (!Z4_INQ::z5_file.First(Z4_INQ::z5, szLastMatch))
  128.             return ;
  129.         SetVlistPos((LONG)Z4_INQ::z5_file.RecordNo());
  130.         SetCurrent(FID(STR_SEARCH));
  131.         }
  132.     return ;
  133. }
  134.  
  135.  
  136. //----------------------------------------------------------------------------
  137. //   Description:    Display detail windows
  138. //    Parameters:
  139. //       Returns:    TRUE if successful.
  140. //----------------------------------------------------------------------------
  141. BOOL FN_M ZI_Z5::Detail()
  142. {
  143.     if (!Z4_INQ::z5_file.Record(Z4_INQ::z5, lCurrent))
  144.         return FALSE;
  145.  
  146.     if (Z4_INQ::z5.cCities == 1)
  147.         {
  148.         if (!Z4_INQ::cs_file.Record(Z4_INQ::cs, Z4_INQ::z5.arecid[0]))
  149.             return FALSE;
  150.  
  151.         PZI_CS_DETAIL pzi_cs_detail = new ZI_CS_DETAIL(Z4_INQ::cs);
  152.         if (pzi_cs_detail == NULL)
  153.             return ErrorNoMem();
  154.         else if (pzi_cs_detail->IsValid())
  155.             pzi_cs_detail->Show();
  156.  
  157.         return TRUE;
  158.         }
  159.     PZI_CS_LIST pzi_cs_list = new ZI_CS_LIST(Z4_INQ::z5.cCities, Z4_INQ::z5.arecid, Z4_INQ::z5.szZip5);
  160.     if (pzi_cs_list == NULL)
  161.         return ErrorNoMem();
  162.     else if (pzi_cs_list->IsValid())
  163.         pzi_cs_list->Show();
  164.     return TRUE;
  165. }
  166.  
  167.  
  168. //----------------------------------------------------------------------------
  169. //   Description:    Destroy object. Free any resources used by object.
  170. //                          Normally called by destructor.
  171. //                        Should allow multiple calls from various classes.
  172. //                        A class should almost always re-init its variables when 
  173. //                        it is destroyed to prevent accidents.
  174. //    Parameters:    fDestroyAll        Destroy parents also?
  175. //                                            Default is TRUE.
  176. //       Returns:    TRUE if successful.
  177. //----------------------------------------------------------------------------
  178. BOOL FN_M ZI_Z5::Destroy(BOOL fDestroyAll)
  179. {
  180.     ZI_Z5::Initialize(CL_INIT_CLASS_VARS);
  181.     if (fDestroyAll)                            // Destroy parent.
  182.         ZI_Z5_PARENT::Destroy(fDestroyAll);
  183.     return TRUE;
  184. }
  185.  
  186.  
  187. //----------------------------------------------------------------------------
  188. //   Description:    Initialize object. 
  189. //                          Normally called by constructor.
  190. //                        Should allow multiple calls from various classes.
  191. //    Parameters:    sInit        Initialization code. May be one of the following:
  192. //                                        CL_INIT_CLASS            Reset class variables and
  193. //                                                                    and dynamic allocations for
  194. //                                                                    this class only.
  195. //                                        CL_INIT_CLASS_VARS    Reset class variables for
  196. //                                                                    this class only.
  197. //                                        CL_INIT_VARS            Reset class variables for
  198. //                                                                    this class only.
  199. //                                        CL_INIT_ALL                Initialize class and all 
  200. //                                                                    parent class, including
  201. //                                                                    dynamic memory allocation.
  202. //                                    Default is CL_INIT_ALL
  203. //       Returns:    TRUE if successful.
  204. //----------------------------------------------------------------------------
  205. BOOL FN_M ZI_Z5::Initialize(SHORT sInit)
  206. {
  207.     if (sInit == CL_INIT_VARS || sInit == CL_INIT_ALL)
  208.         ZI_Z5_PARENT::Initialize(sInit);
  209.  
  210.     szLastMatch[0] = '\0';
  211.     lCurrent = 0;
  212.     lRecords = 0;
  213.     fInit = FALSE;
  214.     pcszZip5 = NULL;
  215.     return TRUE;
  216. }
  217.  
  218.  
  219. //----------------------------------------------------------------------------
  220. //   Description:    
  221. //    Parameters:
  222. //       Returns:    TRUE if successful.
  223. //----------------------------------------------------------------------------
  224. BOOL FN_M ZI_Z5::Query(PZN_VLIST_ELEM pzn_vlist_elem)
  225. {
  226.     pzn_vlist_elem->pszBuf = szFormat;
  227.     szFormat[0] = '\0';
  228.     if (!Z4_INQ::z5_file.Record(Z4_INQ::z5, pzn_vlist_elem->lId))
  229.         return FALSE;
  230.     BestCity();
  231.     sprintf(szFormat, "\t%s\t%s\t%s",
  232.         Z4_INQ::z5.szZip5,
  233.         Z4_ST_FILE::Abbreviation(Z4_INQ::cs.state),
  234.         Z4_INQ::cs.szCity);
  235.     return TRUE;
  236. }
  237.  
  238.  
  239. //----------------------------------------------------------------------------
  240. //   Description:    
  241. //    Parameters:
  242. //       Returns:    TRUE if successful.
  243. //----------------------------------------------------------------------------
  244. BOOL FN_M ZI_Z5::Select()
  245. {
  246.     if (!Z4_INQ::z5_file.Record(Z4_INQ::z5, lCurrent))
  247.         return FALSE;
  248.  
  249.     SendMessage(ZiMainWindow(), ZI_MSG_ZIP5, NULL, (PVOID)Z4_INQ::z5.szZip5);
  250.     if (Z4_INQ::z5.cCities > 1)
  251.        {
  252.        SendMessage(ZiMainWindow(), ZI_MSG_STATE, NULL, (PVOID)NULL);
  253.        SendMessage(ZiMainWindow(), ZI_MSG_CITY, NULL, (PVOID)NULL);
  254.        }
  255.     else
  256.        {
  257.        if (Z4_INQ::cs_file.Record(Z4_INQ::cs, Z4_INQ::z5.arecid[0]))
  258.            {
  259.            SendMessage(ZiMainWindow(), ZI_MSG_STATE, NULL, (PVOID)Z4_ST_FILE::Abbreviation(Z4_INQ::cs.state));
  260.             PCSZ pcszCity = (Z4_INQ::cs.facility == Z4_FACILITY_OTHER ? Z4_INQ::cs.szLastLineName: Z4_INQ::cs.szCity);
  261.            SendMessage(ZiMainWindow(), ZI_MSG_CITY, NULL, (PVOID)pcszCity);
  262.            }
  263.        }
  264.     return TRUE;
  265. }
  266.  
  267.  
  268. //----------------------------------------------------------------------------
  269. //   Description:    Event monitor function.
  270. //    Parameters:    msg        Event code
  271. //                        pv1            Data pointer 1
  272. //                        pv2            Data pointer 2
  273. //       Returns:    Event code
  274. //----------------------------------------------------------------------------
  275. ZN_MSG FN_M ZI_Z5::User(ZN_MSG msg, PVOID, PVOID pv2)
  276. {
  277.     switch (msg)
  278.         {
  279.         case ZN_MSG_INIT:
  280.             fInit = TRUE;
  281.             if (pcszZip5)
  282.                 {
  283.                 SetString(FID(STR_SEARCH), pcszZip5);
  284.                 CheckMatch();
  285.                 }
  286.             SetCurrent(FID(STR_SEARCH));
  287.             return msg;
  288.  
  289.         case ZN_MSG_TERMINATE:
  290.             return msg;
  291.  
  292.         case ZN_MSG_VLIST_INIT:
  293.             {
  294. static int aiTabstops[] = { 2, 9, 13, 0, 0 };
  295.             PZN_VLIST_INIT pzn_vlist_init = (PZN_VLIST_INIT)pv2;
  296.             pzn_vlist_init->lElems = lRecords = (LONG)Z4_INQ::z5_file.Records();
  297.             pzn_vlist_init->fs = ZN_VLIST_SINGLE|ZN_VLIST_TITLE;
  298.             pzn_vlist_init->aiTabstops = aiTabstops;
  299.             }
  300.             return msg;
  301.  
  302.         case ZN_MSG_VLIST_TITLE:
  303.             {
  304.             PZN_VLIST_ELEM pzn_vlist_elem = (PZN_VLIST_ELEM)pv2;
  305.             pzn_vlist_elem->pszBuf = szFormat;
  306.             strcpy(szFormat, "\tZIP\tST\tPreferred City Name");
  307.             }
  308.             return msg;
  309.         }
  310.     if (IsError())                                // Error condition
  311.         return msg;
  312.     switch (msg)
  313.         {
  314.         case ZN_MSG_STRING_CHANGE:
  315.             CheckMatch();
  316.             break;
  317.  
  318.         case ZN_MSG_VLIST_QUERY:
  319.             Query((PZN_VLIST_ELEM)pv2);
  320.             break;
  321.  
  322.         case ZN_MSG_VLIST_SELECT:
  323.             {
  324.             PZN_VLIST_ELEM pzn_vlist_elem = (PZN_VLIST_ELEM)pv2;
  325.             lCurrent = pzn_vlist_elem->lId;
  326.             }
  327.             // Fall through
  328.  
  329.         case ZN_MSG_VLIST_CURRENT:
  330.             {
  331.             PZN_VLIST_ELEM pzn_vlist_elem = (PZN_VLIST_ELEM)pv2;
  332.             LONG lRec = pzn_vlist_elem->lId;
  333.             sprintf(szFormat, "ZIP %ld of %ld", lRec+1, lRecords);
  334.             SetHelp(szFormat);
  335.             }
  336.             break;
  337.  
  338.         case ZN_MSG_VLIST_DBL_CLK:
  339.             {
  340.             PZN_VLIST_ELEM pzn_vlist_elem = (PZN_VLIST_ELEM)pv2;
  341.             lCurrent = pzn_vlist_elem->lId;
  342.             }
  343.             // Fall through
  344.         case TB_DETAIL:
  345.             Detail();
  346.             break;
  347.  
  348.         case ZN_MSG_HELP:
  349.             return ZN_MSG_NO_HELP;
  350.  
  351.         case TB_CLOSE:
  352.             Close();
  353.             break;
  354.  
  355.         case TB_SELECT:
  356.             Select();
  357.             Close();
  358.             break;
  359.  
  360.         case TB_HELP:
  361.             NotDone();
  362.             break;
  363.         }
  364.     return msg;
  365. }
  366. //----------------------------------------------------------------------------
  367. //------------------------------- End of File --------------------------------
  368. //----------------------------------------------------------------------------
  369.